<?php

class GcalEvent
{
	public function __construct($cal, $event) 
	{
  		$this->cal = $cal;
		$this->event = $event;
	}	
	
	function get()
	{
        $retVal = true;
        
		$eventURL = 'http://www.google.com/calendar/feeds/' .
                    urlencode($this->cal) . 
					'/public/full/' .
					urlencode($this->event);
		        
		$event = file_get_contents($eventURL);

        if ($event === false)
        {
            $retVal = false;
        }
        else
        {
            $this->eventXML = new SimpleXmlElement($event);
            $this->gd = $this->eventXML->children('http://schemas.google.com/g/2005');

            if (strlen ((string) $this->eventXML->content) > 0)
            {
                $this->details = new SimpleXmlElement ((string) $this->eventXML->content);
            }
        }
        
		return $retVal;
	}
	
	function title()
	{
		return (string) $this->eventXML->title;
	}

	function content()
	{
		return (string) $this->eventXML->content;
	}

	function where()
	{
		return $this->gd->where->attributes()->valueString;
	}

	function date()
	{
		return $this->startTime();
	}
	
	function startTime()
	{
		return new DateTime ($this->gd->when->attributes()->startTime);
	}

	function endTime()
	{
		return new DateTime ($this->gd->when->attributes()->endTime);
	}
	
	function postcode()
	{
		return $this->details->postcode;
	}
	
	function address()
	{
		return $this->details->address;
	}
	
	function description()
	{
		return $this->details->description;
	}
	
    function link()
	{
		return $this->details->link;
	}
}
?>